package org.tczs93.lunce.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tczs93.lunce.lucene.LuceneIndex;
import org.tczs93.lunce.lucene.LuceneIndexer;
import org.tczs93.lunce.lucene.SearchBuilder;
import org.tczs93.lunce.model.Customer;
import java.util.List;

/**
 * @author ：tao.li
 * @description：
 * @date ：Created in 2021/9/3 13:56
 */
@RestController
public class TestController {

    @Autowired
    private LuceneIndex luceneIndex;

    @GetMapping("/lucene/create")
    public String createIndex(){
        Customer customer = new Customer();
        customer.setName("嘿嘿嘿嗯");
        customer.setDesc("而微软顶顶顶顶顶是东北");
        customer.setPrice(234.2F);
        luceneIndex.insertDocument(customer);
        return "SUCCESS";
    }

    @GetMapping("/lucene/find")
    public String searchIndex(String column,String str) {
        List<Customer> classes = luceneIndex.findDocument(column,str,Customer.class);
        for(Customer user : classes)
            System.out.println(user.toString());
        return "SUCCESS";
    }
}
